﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace LPV_POS.mh_pos
{
    public partial class mh_khuyenmaihanghoa : DevExpress.XtraEditors.XtraForm
    {
        thuvien tv;
        DataTable tb;
        string[] s;
        object[] o;
        string str_tuychon = "";
        public DataTable tbHH_KM;

        #region "   select danh sach hang hoa theo nhom chu"
        private DataTable f_selectdshanghoatheonhomchu(string manhomchuhanghoa)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@MANHOMCHU" };
            o = new object[] { 1, 4, manhomchuhanghoa };
            tb = tv.SP_SelectDataTable("sp_mh_dmnhomchuhh", s, o);
            DataView dv_temp = tb.DefaultView;
            dv_temp.Sort = "OBJID DESC";
            return dv_temp.ToTable();
        }
        #endregion

        #region "   select danh sach nhom chu hh"
        private DataTable f_selectdsnhomchuhh()
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose" };
            o = new object[] { 1, 1 };
            tb = tv.SP_SelectDataTable("sp_mh_dmnhomchuhh", s, o);
            DataView dv_temp = tb.DefaultView;
            dv_temp.Sort = "OBJID DESC";
            return dv_temp.ToTable();
        }
        #endregion

        #region "   select danh sach nhom hang"
        private DataTable f_selectdsnhomhh()
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose" };
            o = new object[] { 1, 1 };
            tb = tv.SP_SelectDataTable("sp_mh_dmnhomhanghoa", s, o);
            DataView dv_temp = tb.DefaultView;
            dv_temp.Sort = "OBJID DESC";
            return dv_temp.ToTable();
        }
        #endregion

        #region "   select danh sach hang hoa"
        private DataTable f_selectdshanghoa()
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose" };
            o = new object[] { 1, 6 };
            tb = tv.SP_SelectDataTable("sp_mh_dmkhuyenmai", s, o);
            DataView dv_temp = tb.DefaultView;
            DataColumn col = new DataColumn("FLAG", Type.GetType("System.Boolean"));
            dv_temp.Table.Columns.Add(col);
            dv_temp.Sort = "TENHHKM";
            return dv_temp.ToTable();
        }
        #endregion

        #region "   select danh sach hang hoa theo nhom hang hoa"
        private DataTable f_selectdshanghoatheonhom(string manhomhanghoa)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@OBJID" };
            o = new object[] { 1, 5, manhomhanghoa };
            tb = tv.SP_SelectDataTable("sp_mh_dmnhomhanghoa", s, o);
            DataView dv_temp = tb.DefaultView;
            dv_temp.Sort = "OBJID DESC";
            return dv_temp.ToTable();
        }
        #endregion

        #region "   mh_khuyenmaihanghoa"
        public mh_khuyenmaihanghoa()
        {
            InitializeComponent();
        }
        #endregion

        #region "   mh_khuyenmaihanghoa"
        public mh_khuyenmaihanghoa(string tuychon)
        {
            InitializeComponent();
            str_tuychon = tuychon;
            switch (tuychon)
            {
                case "Nhóm chủ":
                    {
                        luoi_hanghoakhuyenmai.MainView = grid_nhomchuhanghoa;
                        luoi_hanghoakhuyenmai.DataSource = null;
                        luoi_hanghoakhuyenmai.DataSource = f_selectdsnhomchuhh();
                        break;
                    }
                case "Nhóm hàng":
                    {
                        luoi_hanghoakhuyenmai.MainView = grid_nhomhanghoa;
                        luoi_hanghoakhuyenmai.DataSource = null;
                        luoi_hanghoakhuyenmai.DataSource = f_selectdsnhomhh();
                        break;
                    }
                case "Hàng hóa":
                    {
                        luoi_hanghoakhuyenmai.MainView = grid_hanghoa;
                        luoi_hanghoakhuyenmai.DataSource = null;

                        col_checkhanghoa.FieldName = "FLAG";
                        col_checkhanghoa.Caption = "";

                        luoi_hanghoakhuyenmai.DataSource = f_selectdshanghoa();

                        break;
                    }
            }
        }
        #endregion

        #region "   mh_khuyenmaihanghoa_Load"
        private void mh_khuyenmaihanghoa_Load(object sender, EventArgs e)
        {

        }
        #endregion

        #region "   bton_chon_Click"
        private void bton_chon_Click(object sender, EventArgs e)
        {
            switch (str_tuychon)
            {
                case "Nhóm chủ":
                    {
                        string manhomchuhanghoa = grid_nhomchuhanghoa.GetRowCellValue(grid_nhomchuhanghoa.FocusedRowHandle, col_manhomchu).ToString() + "";
                        tbHH_KM = f_selectdshanghoatheonhomchu(manhomchuhanghoa);
                        break;
                    }
                case "Nhóm hàng":
                    {
                        string manhomhanghoa = grid_nhomhanghoa.GetRowCellValue(grid_nhomhanghoa.FocusedRowHandle, col_manhomhang).ToString() + "";
                        tbHH_KM = f_selectdshanghoatheonhom(manhomhanghoa);
                        break;
                    }
                case "Hàng hóa":
                    {
                        DataView dv = (DataView)grid_hanghoa.DataSource;
                        dv.RowFilter = "FLAG=True";
                        tbHH_KM = dv.ToTable();
                        break;
                    }
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        #endregion

        #region "   bton_thoat_Click"
        private void bton_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

    }
}